#ifndef __GATEWAY_H__
#define	__GATEWAY_H__

#include <iostream>
#include <deque>
#include <list>

#include <sys/socket.h>
#include <sys/types.h>
#include <sys/epoll.h>
#include <netinet/in.h>
#include <pthread.h>
#include <netinet/tcp.h> 
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <arpa/inet.h>
#include <unistd.h>

#define BUFSIZE		128

typedef enum {
	TO_SERVER = 0,
	TO_CLIRNT,
}MsgFlag;

using namespace std;

typedef struct message{
	int fd;
	unsigned int length;
	char data[BUFSIZE];
}Message;

typedef struct {
	Message msg;
	MsgFlag flag;
}QueInfo;

class  GateWay{
public:
	GateWay();
	~GateWay(){;}
	
	bool InitSer();
	bool InitCli();
	void AddEvent(int fd, int flag);
	void DelEvent(int fd);
	void AddList(int fd);
	void DelList(int fd);
	void ClearList();
	
	void SendMsg();
	
	void MainLoop();
	
private:
	int lis_fd;
	int ser_fd;
	int cli_fd;
	unsigned int pross_id;
	int epfd;
	unsigned int con_cnt;
	
	deque<QueInfo>  Queue;
	deque<QueInfo>::iterator dq;
	list<int>  FdList;
};

void delay(unsigned int ms);


#endif